From 09ddbb1ce580051ada4dd96c6667fbd3e6f10499 Mon Sep 17 00:00:00 2001 From: Ewan Mellor Date: Thu, 7 Dec 2006 12:07:53 +0000 Subject: [PATCH] The HTTP service used for SEXPR based RPC calls currently serializes all incoming client requests. Since some requests can take non-trivial time blocking out other clients in this way has bad consequences. The attached patch makes XenD spawn a new thread to handle each incoming HTTP request. This same approach is already taken in the XML-RPC service in XenD so I don't anticipate any multi-thread issues (at least none which don't already exist). Signed-off-by: Daniel P. Berrange --- tools/python/xen/web/httpserver.py | 44 +++++++++++++++++++----------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/tools/python/xen/web/httpserver.py b/tools/python/xen/web/httpserver.py index bcf5dbd6b1..2326a2b875 100644 --- a/tools/python/xen/web/httpserver.py +++ b/tools/python/xen/web/httpserver.py @@ -264,7 +264,32 @@ class HttpServerRequest(http.HttpRequest): s += x + "/" self.write(' %s/' % (s, x)) self.write("") - + +class HttpServerClient: + + def __init__(self, server, sock, addr): + self.server = server + self.sock = sock + self.addr = addr + + def process(self): + thread = threading.Thread(target=self.doProcess) + thread.setDaemon(True) + thread.start() + + def doProcess(self): + try: + rp = RequestProcessor(self.server, self.sock, self.addr) + rp.process() + except SystemExit: + raise + except Exception, ex: + print 'HttpServer>processRequest> exception: ', ex + try: + self.sock.close() + except: + pass + class HttpServer: backlog = 5 @@ -286,8 +311,8 @@ class HttpServer: while not self.closed: (sock, addr) = self.accept() - self.processRequest(sock, addr) - + cl = HttpServerClient(self, sock, addr) + cl.process() def stop(self): self.close() @@ -314,19 +339,6 @@ class HttpServer: except: pass - def processRequest(self, sock, addr): - try: - rp = RequestProcessor(self, sock, addr) - rp.process() - except SystemExit: - raise - except Exception, ex: - print 'HttpServer>processRequest> exception: ', ex - try: - sock.close() - except: - pass - def getServerAddr(self): return (socket.gethostname(), self.port) -- 2.30.2